package com.huabo.fxgl.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hbfk.util.JsonBean;
import com.huabo.fxgl.entity.Organization;
import com.huabo.fxgl.entity.RiskAssplan;
import com.huabo.fxgl.service.IRiskAssplanRiskService;
import com.huabo.fxgl.service.IRiskAssplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;


@RestController
//@RequestMapping("/pggl")
@Api(tags = "风险评估 - 评估任务")
@Slf4j
public class RiskAssTaskController {
    @Autowired
    private IRiskAssplanService riskAssplanService;
    @Autowired
    private IRiskAssplanRiskService riskAssplanRiskService;

    /*
     * 评估计划查询
     * @param plancode 计划编号
     * @param planName 计划名称
     * @param endDate  计划结束时间02
     * @param endDateS 计划结束时间01
     * @param starDate 计划开始时间02
     * @param starDateS 计划开始时间01
     * @param planType  计划类型
     * @param planStatus 计划状态
     * @param
     * @return
     */
    @RequestMapping(value = "/pggl/riplanlist")
    @ApiOperation(value = "风险评估 - 评估任务 - 返回列表数据 /pggl/riplanlist")
    public JsonBean riplanlist(@ApiParam(name = "pageNumber", value = "pageNumber") @RequestParam(defaultValue = "1") Integer pageNumber,
                               @ApiParam(name = "organization", value = "organization") Organization organization,
                               @ApiParam(name = "organization", value = "organization") RiskAssplan riskAssplan,
                               @ApiParam(name = "limit", value = "limit") @RequestParam(defaultValue = "15") Integer limit,
                               String choiceSearch) {
        IPage page = new Page<>(pageNumber, limit);//分页设置
        String orgid = null;//存储组织ID
        if (organization != null && organization.getOrderid() != null) {
            orgid = organization.getOrgid().toString();
        }
        IPage<RiskAssplan> pageBean = riskAssplanService.findAll(page, riskAssplan, orgid);

        JsonBean jsonBean = new JsonBean();
        jsonBean.setCode(200);
        Map result = new HashMap();
            /*if (choiceSearch == null || "".equals(choiceSearch)){
                result.put("choiceSearch","hide");
            } else {
                result.put("choiceSearch", choiceSearch );
            }*/
        result.put("choiceSearch", choiceSearch == null ? "hide" : choiceSearch);
        result.put("pageBean", pageBean);
        result.put("pageNumber", pageNumber);
//            if (riskAssplan==null)
//                riskAssplan = new RiskAssplan();
        result.put("plancode", riskAssplan == null ? null : riskAssplan.getPlancode());
        result.put("planName", riskAssplan == null ? null : riskAssplan.getPlanName());
        result.put("endDate", riskAssplan == null || riskAssplan.getEndDate() == null ? null : riskAssplan.getEndDate().toLocalDate());
        result.put("starDate", riskAssplan == null || riskAssplan.getStartDate() == null ? null : riskAssplan.getStartDate().toLocalDate());
        result.put("planType", riskAssplan == null ? null : riskAssplan.getPlanType());
        result.put("planStatus", riskAssplan == null ? null : riskAssplan.getPlanStatus());
        jsonBean.setData(result);
        return jsonBean;
    }


}